﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;

namespace YouHP.SqlServerDAL
{
    public class Transcation
    {
        SqlConnection conn = new SqlConnection(Common.ConnStr);
        SqlTransaction ts;

        #region 单件模式
        static Transcation _Instance;

        public static Transcation Instance
        {
            get
            {
                if (_Instance == null)
                {
                    _Instance = new Transcation();
                }
                return _Instance;
            }
        }
        #endregion

        public void Create()
        {
            conn.Open();
            ts = conn.BeginTransaction();
        }

        public void Rollback()
        {
            ts.Rollback();
            conn.Close();
        }

        public void Commit()
        {
            ts.Commit();
            conn.Close();
        }
    }
}
